<script setup>
import { defineEmits, ref } from 'vue'
import { getCategoryList } from '../api/category'

const emit = defineEmits(['clickCategory'])

const category = ref([])
function initCategory() {
  getCategoryList().then((res) => {
    category.value = res.result
  })
}
function clickCategory(id) {
  emit('clickCategory', id)
}
initCategory()
</script>

<template>
  <el-scrollbar class="scroller">
    <div class="scrollbar-flex-content">
      <div
        v-for="item in category"
        :key="item"
        class="scrollbar-demo-item"
        @click="clickCategory(item.id)"
      >
        <img :src="item.icon" alt="" srcset="" class="w-5">
        <div class="font-bold">
          {{ item.name }}
        </div>
      </div>
    </div>
  </el-scrollbar>
</template>

<style scoped>
.scroller {
  height: 80px;
}
.scrollbar-flex-content {
  display: flex;
  color: #000000;
  font-size: 12px;
}
.scrollbar-demo-item {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 100px;
  height: 50px;
  margin: 10px;
  text-align: center;
  border-radius: 4px;
  transition: all 0.6s;
}
.scrollbar-demo-item:hover {
  box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.3);
}
</style>
